package com.chengyu.core.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.chengyu.core.component.OperationLog;
import com.chengyu.core.domain.CommonConstant;
import com.chengyu.core.domain.enums.ShopEnums;
import com.chengyu.core.domain.form.ShopSearchForm;
import com.chengyu.core.domain.form.UmsMemberRegParam;
import com.chengyu.core.entity.CommonPage;
import com.chengyu.core.entity.CommonResult;
import com.chengyu.core.exception.ServiceException;
import com.chengyu.core.model.*;
import com.chengyu.core.request.ShopApplyRequest;
import com.chengyu.core.service.shop.ShopAccountService;
import com.chengyu.core.service.shop.ShopInfoService;
import com.chengyu.core.service.system.SysInviteCodeService;
import com.chengyu.core.service.system.VerifyCodeService;
import com.chengyu.core.util.ip.IpSearch;
import com.chengyu.core.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @title  商户控制器
 * @author wenlj
 * @date   2023/11/09
 */
@Api(tags = "商户控制器")
@Controller
@RequestMapping("/merchant")
public class MerchantController extends UserBaseController {

	@Autowired
	private ShopInfoService shopInfoService;

	@Autowired
	private VerifyCodeService verifyCodeService;
	@Autowired
	private SysInviteCodeService sysInviteCodeService;

	@Autowired
	protected ShopAccountService shopAccountService;




//    @ApiOperation(value = "商户入驻申请")
//    @RequestMapping(value = "/settled/apply", method = RequestMethod.POST)
//    public CommonResult<String> settledApply(@RequestBody @Validated MerchantSettledApplyRequest request) {
//        if (merchantService.settledApply(request)) {
//            return CommonResult.success();
//        }
//        return CommonResult.failed();
//    }

//	@ApiOperation(value = "店铺详情")
//	@ResponseBody
//	@RequestMapping(value="/get", method=RequestMethod.GET)
//	public CommonResult<UmsShopInfo> getList() throws ServiceException {
//		UmsShopInfo shopInfo = shopInfoService.getShopInfo(getCurrentMember());
//		return CommonResult.success(shopInfo);
//	}
//


//	id: 11
//	type: 1
//	realname: 11
//	idcard: 111
//	cardImg: https://qiniu.ccchongya.com/chongya%2F1699246304139.jpg
//	weixin: 1231231
//	brandImg:
//	phone:
//	produce: 11111111111111111
//	logo: https://qiniu.ccchongya.com/chongya%2F1699246361251.png
//	address: 111111
//	status: 1
//	name: 电偶名
//	remark: 111111111111
//	addressArr[0]: 110000
//	addressArr[1]: 110100
//	addressArr[2]: 110101
//	province: 北京市
//	provinceCode: 110000
//	city: 市辖区
//	cityCode: 110100
//	area: 东城区
//	areaCode: 110101
//	addTime:
//	updTime:

	@OperationLog
	@ApiOperation(value = "申请入驻-提交审核")
	@ResponseBody
	@RequestMapping(value={"/applyNew"}, method=RequestMethod.POST)
	public CommonResult<Integer> applyNew(ShopApplyRequest shopApplyRequest) throws Exception {
		UmsMember member = getCurrentMember();
		shopApplyRequest.setMemberId(member.getId());
		shopApplyRequest.setMemberName(member.getCode());

		UmsShopInfo shopInfo = new UmsShopInfo();

		BeanUtil.copyProperties(shopApplyRequest, shopInfo);
		Integer shopInfoId = shopInfoService.applyShopNew(getCurrentMember(), shopInfo);




		return CommonResult.success(1);


	}

	@OperationLog
	@ApiOperation(value = "申请入驻信息")
	@ResponseBody

	@RequestMapping(value={"/applyInfo"}, method=RequestMethod.GET)

	public CommonResult<UmsShopInfo> applyInfo(@RequestParam(value = "shoptype", defaultValue = "1") Integer shoptype) throws Exception {
		UmsMember member = getCurrentMember();
//		shopInfo.setMemberId(member.getId());
//		shopInfo.setMemberName(member.getCode());
//		Integer shopInfoId = shopInfoService.getShopInfoList(getCurrentMember(), shopInfo);
		ShopSearchForm form  = new ShopSearchForm();

		form.setMemberId(member.getId());
//		form.setNotStatus(4);
		form.setShoptype(shoptype);
		form.setSort("id desc");
		List<UmsShopInfo> list = shopInfoService.getShopInfoList(form, 1, 1000);
		UmsShopInfo shopInfo =  CollectionUtil.isNotEmpty(list) ? list.get(0) : null;

		return CommonResult.success(shopInfo,"success");


	}


//	@OperationLog
//	@ApiOperation(value = "申请入驻-提交审核")
//	@ResponseBody
//	@RequestMapping(value={"/submitShopInfo"}, method=RequestMethod.POST)
//	public CommonResult<String> submitShopInfo(UmsShopInfo shopInfo) throws Exception {
//		shopInfoService.submitShopInfo(shopInfo);
//		return CommonResult.success(null);
//	}
}







